<?php ob_start();
if (!isset($_SESSION)) {
  session_start();
  if(!isset($_SESSION['MM_Username']))header("location:../../index.php");
}
		//if(isset($_POST)) var_dump($_POST);
?>
<?php 
	require_once('../../Connections/microassur.php'); 
	require_once('../../utils/fonctions.php');	
	
	//var_dump($_POST);
	if(isset($_SESSION['iduser'])){
		//$idAgent = idAgent($database_microassur, $microassur, $_SESSION['iduser']); //var_dump($idAgent);
		//var_dump($_SESSION['iduser']);
	}
?>

<?php 
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$currentPage = $_SERVER["PHP_SELF"];

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

/********************************DEBUT FONCTIONS****************************/
function idGarantie_garantiesouscrite($database_microassur, $microassur, $Identifiant_contrat){
	$query_rs = "SELECT Identifiant_garantie FROM garantiesouscrite WHERE Identifiant_contrat = $Identifiant_contrat";
	$rs = mysql_query($query_rs, $microassur) or die(mysql_error());
	$row_rs = mysql_fetch_assoc($rs);
	mysql_free_result($rs);
	return $row_rs['Identifiant_garantie'];
}

function idProduit_garantie($database_microassur, $microassur, $Identifiant_garantie){
	$query_rs = "SELECT Identifiant_produit FROM garantie WHERE Identifiant_garantie = $Identifiant_garantie";
	$rs = mysql_query($query_rs, $microassur) or die(mysql_error());
	$row_rs = mysql_fetch_assoc($rs);
	mysql_free_result($rs);
	return $row_rs['Identifiant_produit'];
}

function idOffre_produit($database_microassur, $microassur, $Identifiant_produit){
	$query_rs = "SELECT Identifiant_offre FROM produit WHERE Identifiant_produit = $Identifiant_produit";
	$rs = mysql_query($query_rs, $microassur) or die(mysql_error());
	$row_rs = mysql_fetch_assoc($rs);
	mysql_free_result($rs);
	return $row_rs['Identifiant_offre'];
}

if(isset($_POST['Identifiant_contrat'])){
	$idGarantie = idGarantie_garantiesouscrite($database_microassur, $microassur, GetSQLValueString($_POST['Identifiant_contrat'], "int"));
}
if(isset($idGarantie)){
	$idProduit = idProduit_garantie($database_microassur, $microassur, intval($idGarantie));
}
if(isset($idGarantie)){
	$idOffre = idOffre_produit($database_microassur, $microassur, $idProduit);
}

/********************************FIN FONCTIONS****************************/

$erreurDelai = false;

// Récupérer dans les conditions de vente de type délai, les délais de préavis de résiliation.
if(isset($_POST['Identifiant_contrat']) && isset($_POST['Motif_evenement'])){
	mysql_select_db($database_microassur, $microassur);
	$query_rs3 = "SELECT conditionvente.Code_condition_vente, conditionvente.Type_condition_vente, conditionvente.Identifiant_offre, 
					conditionvente.Identifiant_produit, conditionvente.Valeur_condition_vente 
					FROM conditionvente, contrat 
					WHERE conditionvente.Identifiant_offre= '". @$idOffre ."'
					AND conditionvente.Type_condition_vente='D' 
					AND conditionvente.Code_condition_vente='RESIL'
					AND contrat.Identifiant_contrat='" . $_POST['Identifiant_contrat'] . "'
					AND contrat.Date_effet_contrat >= conditionvente.Date_debut_condition_vente
					AND (contrat.Date_effet_contrat <= conditionvente.Date_fin_condition_vente OR conditionvente.Date_fin_condition_vente IS NULL)  
					";
	$query_limit_rs3 = $query_rs3;
	$rs3 = mysql_query($query_limit_rs3, $microassur) or die(mysql_error());
	$row_rs3 = mysql_fetch_assoc($rs3);
	
	do{
		
		if(strcmp($_POST['Motif_evenement'], 'CO')==0 && isset($_POST['Date_evenement'])){
			$date1 = dateEN2FR($_POST['Date_evenement']);
			$date2 = dateEcheanceContrat($database_microassur, $microassur, GetSQLValueString($_POST['Identifiant_contrat'], "int"));
			$nombreJour = date_diff2($date1, $date2); 
			if($nombreJour<$row_rs3['Valeur_condition_vente']){
				$message = colorer('Préavis de résiliation n’est pas respecté, la résiliation ne peut avoir lieu.', 'false');
				$erreurDelai = true;
			}
		}
		
	}while($row_rs3 = mysql_fetch_assoc($rs3));
} 

// Récupérer dans les conditions de vente de type délai, les délais de préavis de  renonciation.
if(isset($_POST['Identifiant_contrat']) && isset($_POST['Motif_evenement'])){
	mysql_select_db($database_microassur, $microassur);
	$query_rs3 = "SELECT conditionvente.Code_condition_vente, conditionvente.Type_condition_vente, 
					conditionvente.Identifiant_offre, conditionvente.Identifiant_produit, conditionvente.Valeur_condition_vente 
					FROM conditionvente, contrat 
					WHERE conditionvente.Identifiant_offre= '". @$idOffre ."' 
					AND conditionvente.Type_condition_vente='D' 
					AND conditionvente.Code_condition_vente='RENON'
					AND contrat.Identifiant_contrat='" . $_POST['Identifiant_contrat'] . "'
					AND contrat.Date_effet_contrat >= conditionvente.Date_debut_condition_vente
					AND (contrat.Date_effet_contrat <= conditionvente.Date_fin_condition_vente OR conditionvente.Date_fin_condition_vente IS NULL)  
					";
	$query_limit_rs3 = $query_rs3;
	$rs3 = mysql_query($query_limit_rs3, $microassur) or die(mysql_error());
	$row_rs3 = mysql_fetch_assoc($rs3);
	
	do{
		
		if(strcmp($_POST['Motif_evenement'], 'RE')==0 && isset($_POST['Date_evenement'])){
			$date1 = dateEffetContrat($database_microassur, $microassur, GetSQLValueString($_POST['Identifiant_contrat'], "int"));
			$date2 = dateEN2FR($_POST['Date_evenement']);
			$nombreJour = date_diff2($date1, $date2);
			if($nombreJour>$row_rs3['Valeur_condition_vente']){
				$message = colorer('La renonciation intervient après la fin du délai de renonciation, la résiliation ne peut avoir lieu.', 'false');
				$erreurDelai = true;
			}
		}
		
	}while($row_rs3 = mysql_fetch_assoc($rs3));
} 

if(isset($_POST['Date_evenement']) && !empty($_POST['Date_evenement'])){
	$compareDates1 = strcmp(date("Y-m-d"), dateEN2FR($_POST['Date_evenement'])); 
    if(isset($_POST['Identifiant_contrat'])){
		$dateEffetContrat = dateEffetContrat($database_microassur, $microassur, $_POST['Identifiant_contrat']);
		$compareDates2 = strcmp($dateEffetContrat, dateEN2FR($_POST['Date_evenement'])); 
		$dateEcheanceContrat = dateEcheanceContrat($database_microassur, $microassur, $_POST['Identifiant_contrat']);
		$compareDates3 = strcmp($dateEcheanceContrat, dateEN2FR($_POST['Date_evenement'])); 
	}		
}

$soumission = 0;
		
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) { 

if(isset($_POST['Date_evenement']) && empty($_POST['Date_evenement'])){
	$message = colorer("Vous devez saisir la date de résiliation.", "false");
}elseif(!empty($_POST['Date_evenement']) && !datevalider($_POST['Date_evenement'])){
	$message = colorer("Le format de la date de résiliation est JJ-MM-SSAA, JJ étant le jour, MM le mois, SS le siècle, AA l’année.", "false");
}elseif(!empty($_POST['Date_evenement']) && !datevalide($_POST['Date_evenement'])){
	$message = colorer("La date de résiliation est incohérente.", "false");
}elseif(datevalide($_POST['Date_evenement']) && $compareDates1 < 0){
	$message = colorer("La date de résiliation ne peut être postérieure à la date du jour.", "false");
}elseif(datevalide($_POST['Date_evenement']) && $compareDates2 > 0){
	$message = colorer("La date de résiliation ne peut être antérieure à la date d’effet du contrat.", "false");
}elseif(datevalide($_POST['Date_evenement']) && $compareDates3 < 0){
	$message = colorer("La date de résiliation ne peut être postérieure à la date d’échéance du contrat.", "false");
}elseif($erreurDelai == true){
	;
}else{
	  $insertSQL = sprintf("INSERT INTO evenement (Identifiant_evenement, Type_evenement, Sous_type_evenement, Motif_evenement, Reference_evenement, Date_evenement, Identifiant_agent, Identifiant_sinistre, Identifiant_contrat, Identifiant_personne, Identifiant_echeance, Identifiant_prestation) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
						   GetSQLValueString($_POST['Identifiant_evenement'], "int"),
						   GetSQLValueString($_POST['Type_evenement'], "text"),
						   GetSQLValueString($_POST['Sous_type_evenement'], "text"),
						   GetSQLValueString($_POST['Motif_evenement'], "text"),
						   GetSQLValueString($_POST['Reference_evenement'], "text"),
						   GetSQLValueString(dateEN2FR($_POST['Date_evenement']), "date"),
						   GetSQLValueString($_POST['Identifiant_agent'], "int"),
						   GetSQLValueString($_POST['Identifiant_sinistre'], "int"),
						   GetSQLValueString($_POST['Identifiant_contrat'], "int"),
						   GetSQLValueString($_POST['Identifiant_personne'], "int"),
						   GetSQLValueString($_POST['Identifiant_echeance'], "int"),
						   GetSQLValueString($_POST['Identifiant_prestation'], "int"));
	
	  mysql_select_db($database_microassur, $microassur);
	  mysql_query("START TRANSACTION");
	  $Result1 = mysql_query($insertSQL, $microassur) or die(mysql_error());
	  if($Result1){

		$updateSQL2 = sprintf("UPDATE role SET Etat_role='I' WHERE Identifiant_contrat=%s AND Etat_role='A'", GetSQLValueString($_POST['Identifiant_contrat'], "int"));
		$Result2 = mysql_query($updateSQL2, $microassur) or die(mysql_error());
		if($Result2){
			$message = colorer("", "true"); //$message = colorer("Modification rôle, résiliation contrat, prise en compte.", "true");
		}else{
			$message = colorer("Problème modification rôle, résiliation contrat, contactez la DSI.", "false");
		}
		
		$updateSQL4 = sprintf("UPDATE garantiesouscrite SET Etat_garantie_souscrite='I' WHERE Identifiant_contrat=%s", GetSQLValueString($_POST['Identifiant_contrat'], "int"));
		
		$Result4 = mysql_query($updateSQL4, $microassur) or die(mysql_error());
		if($Result4){
			$message = colorer("", "true"); //colorer("Modification garantie souscrite, résiliation contrat, prise en compte.", "true");
		}else{
			$message = colorer("Problème modification garantie souscrite, résiliation contrat, contactez la DSI.", "false");
		}

		if(strcmp($_POST['Motif_evenement'], 'CO')==0){
			$updateSQL3 = sprintf("UPDATE contrat SET Etat_contrat='R' WHERE Identifiant_contrat=%s", 
								GetSQLValueString($_POST['Identifiant_contrat'], "int"));
		}else{
			$updateSQL3 = sprintf("UPDATE contrat SET Etat_contrat='R', Date_echeance_contrat =%s WHERE Identifiant_contrat=%s", 
								GetSQLValueString(dateEN2FR($_POST['Date_evenement']), "date"),
								GetSQLValueString($_POST['Identifiant_contrat'], "int"));
		}
				
		$Result3 = mysql_query($updateSQL3, $microassur) or die(mysql_error());
		if($Result3){
			$message = colorer("La résiliation du contrat est prise en compte.", "true"); // $message = colorer("", "true");
			//unset($_POST);
			//unset($_GET);
		}else{
			$message = colorer("Problème résiliation contrat, contactez la DSI.", "false");
		}
		mysql_query("commit");
		//$deleteGoTo = "../../menu.php";
		//header(sprintf("Location: %s", $deleteGoTo));
	  }else{
	  	mysql_query("rollback");
		$message = colorer("Problème création évènement, résiliation contrat, contactez la DSI.", "false");
	  }
	 //print_r($_POST); 
	}
}

$maxRows_rs1 = 10;
$pageNum_rs1 = 0;
if (isset($_GET['pageNum_rs1'])) {
  $pageNum_rs1 = $_GET['pageNum_rs1'];
}
$startRow_rs1 = $pageNum_rs1 * $maxRows_rs1;

$colname_rs1 = "";
$idCotisation = "";
$cotisationDue = "";
$dontImpayes = "";
$idContrat = "";

if(isset($_POST['Numero_contrat']) && empty($_POST['Numero_contrat'])){
	$message = colorer("Vous devez saisir le numéro de contrat.", "false");
}elseif(isset($_POST['Numero_contrat']) && !veriflibelle1('Numero_contrat')){
	$message = colorer("Numéro de contrat saisi comporte des caractères spéciaux interdits.","false");
}else{
	if ((isset($_POST["MM_rechercher"])) && ($_POST["MM_rechercher"] == "form1")) {
		if (isset($_POST['Numero_contrat']) && !empty($_POST['Numero_contrat']) && verifLibelle1('Numero_contrat')) {
		  $colname_rs1 = IdContrat($database_microassur, $microassur, $_POST['Numero_contrat']); 
		} 
		
		mysql_select_db($database_microassur, $microassur);
		$query_rs1 = sprintf("SELECT * FROM `role`  WHERE Etat_role = 'A' AND Identifiant_contrat = %s", GetSQLValueString($colname_rs1, "int"));
		//$query_limit_rs1 = sprintf("%s LIMIT %d, %d", $query_rs1, $startRow_rs1, $maxRows_rs1);
		$query_limit_rs1 = $query_rs1;
		$rs1 = mysql_query($query_limit_rs1, $microassur) or die(mysql_error());
		$row_rs1 = mysql_fetch_assoc($rs1);
		
		if (isset($_GET['totalRows_rs1'])) {
		  $totalRows_rs1 = $_GET['totalRows_rs1'];
		} else {
		  $all_rs1 = mysql_query($query_rs1);
		  $totalRows_rs1 = mysql_num_rows($all_rs1);
		//$totalPages_rs1 = ceil($totalRows_rs1/$maxRows_rs1)-1;
		
		/**************************/
		mysql_select_db($database_microassur, $microassur);
		$query_rs2 = sprintf("SELECT * FROM `contrat`  WHERE Identifiant_contrat = %s", GetSQLValueString($colname_rs1, "int"));
		$rs2 = mysql_query($query_rs2, $microassur) or die(mysql_error());
		$row_rs2 = mysql_fetch_assoc($rs2);

		$all_rs2 = mysql_query($query_rs2);
		$totalRows_rs2 = mysql_num_rows($all_rs2);
		/**************************/
		
		if( $totalRows_rs2==0){
			$message = colorer("Contrat inexistant.", "false");
		}elseif($totalRows_rs1==0)
			$message = colorer("", "false"); //$message = colorer("Aucun role n'est rattaché à ce contrat.", "false"); 
		}
		
		$etatContrat = EtatContrat($database_microassur, $microassur, $_POST['Numero_contrat']);
		if($etatContrat == 'R'){
			$message = $message = colorer("Le contrat est déjà résilié.", "false");
		}

		if($totalRows_rs1>0 && $etatContrat != 'R'){
		  $idCotisation = IdCotisation($database_microassur, $microassur, $colname_rs1);
		  if(isset($colname_rs1))
			  $dateEffetContrat2 = dateEffetContrat($database_microassur, $microassur, $colname_rs1); 
		  if(isset($idCotisation))
			$cotisationDue = cotisationRestantDue($database_microassur, $microassur, $idCotisation, $dateEffetContrat2);
		  if(isset($idCotisation))
			$dontImpayes = cotisationDontImpayes($database_microassur, $microassur, $idCotisation, $dateEffetContrat2);	
		  $identifiantContrat = $colname_rs1;
		}

	}
}

// Dictionnaire
$query_rs_dico1 = 'SELECT Identifiant_table FROM dictionnaire where Code_table="M0009"';
$rs_dico1 = mysql_query($query_rs_dico1, $microassur) or die(mysql_error());
$row_rs_dico1 = mysql_fetch_assoc($rs_dico1);
$num_row = $row_rs_dico1['Identifiant_table'];

// Elements dictionnaire rattachés
$query_rs_dico2 = "SELECT Code_element, Nom_element FROM elementdico where Identifiant_table = '$num_row'";
$rs_dico2 = mysql_query($query_rs_dico2, $microassur) or die(mysql_error());
$row_rs_dico2 = mysql_fetch_assoc($rs_dico2);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=8" />
			<title>Résiliation de contrat</title>
			<link rel="stylesheet" type="text/css" href="../../css/main.css" />
            <link rel="stylesheet" type="text/css" href="list.css" />
			<!--[if IE 7]>
            	<link rel="stylesheet" type="text/css" href="../../css/ie7.css" />
            	<link rel="stylesheet" type="text/css" href="form_ie7.css" />
            <![endif]-->
            <link type="text/css" href="../../css/custom-theme/jquery-ui-1.8.11.custom.css" rel="stylesheet" />	
            <script type="text/javascript" src="../../js/jquery-1.5.1.min.js"></script>
            <script type="text/javascript" src="../../js/jquery-ui-1.8.11.custom.min.js"></script>
            <script type="text/javascript" src="../../js/jquery.ui.datepicker-fr.js"></script>
            <script type="text/javascript" src="../../js/scripts.js"></script>
	</head>

<body>
<div id="sf_menu1">
	<h3>Production</h3>

<?php
	if(isset($message) && !empty($message)){
		echo $message;
	}
	$nommodule="Résiliation contrat";
	//$nommodule2="Liste des partenaires";
	$nom_module_saisie="Eléments résiliation";
?>
</div>
<div class="cleared"></div>

<div class="corps1">

<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  <div id="rech">
	  <label>N°&nbsp;CONTRAT</label>
	  <input id="Numero_contrat"  class="resize_1" type="text" name="Numero_contrat" value="<?php if(isset($_POST['Numero_contrat'])){ echo remind_text('Numero_contrat');} ?>" size="32" maxlength="20" />
    <div class="bt">
        <span class="btleft"></span>
        <input type="submit" name="Rechercher" value="Rechercher" class="resizeall btmiddle"/>
        <span class="btright"></span>
    </div>  
  </div>
  <input type="hidden" name="identifiant_contrat" id="identifiant_contrat" value="<?php if(isset($_POST['Numero_contrat'])){ echo IdContrat($database_microassur, $microassur, $_POST['Numero_contrat']); } ?>" />
  <input type="hidden" name="identifiant_cotisation" id="identifiant_cotisation" value="<?php if(isset($_POST['Numero_contrat'])){ echo IdCotisation($database_microassur, $microassur, IdContrat($database_microassur, $microassur, $_POST['Numero_contrat'])); } ?>" />
  <input type="hidden" name="MM_rechercher" value="form1" />
</form>

<div id="br"></div>

<?php 
if(isset($row_rs1['Identifiant_personne']) && !empty($row_rs1['Identifiant_personne']) && $etatContrat == 'A'){ 
?>

<?php
} // Fin if(isset($row_rs1['Identifiant_personne']) && !empty($row_rs1['Identifiant_personne']))
?>

<div id="br"></div>

<form action="<?php echo $editFormAction; ?>" method="post" name="form2" id="form2">
	<div class="imgleft"></div>
	<div class="imgmiddle">
    <div class="btn">
    	<span class="btnleft"></span>
        <span class="btnmiddle">
        	<h5><?php echo $nommodule; ?></h5>
        </span><span class="btnright"></span>
    </div>
  	<div class="btn1">
    	<span class="btnleft"></span>
        <span class="btnmiddle">
        	<h5><?php echo $nom_module_saisie; ?></h5>
        </span>
        <span class="btnright"></span>
    </div>
	<div class="formulaire">
  <table class="tabform">
    <tr>
      <td>MOTIF RESILIATION</td>
      <td>
      <!--select name="Motif_evenement" onchange="Choix(this.form);">
        <option value="AL" <?php echo remind_select('Motif_evenement', 'AL'); ?>>Age limite atteint</option>
        <option value="CC" <?php echo remind_select('Motif_evenement', 'CC'); ?>>Changement de couverture</option>
        <option value="CO" <?php echo remind_select('Motif_evenement', 'CO'); ?>>Contractuelle</option>
        <option value="NP" <?php echo remind_select('Motif_evenement', 'NP'); ?>>Non paiement</option>
        <option value="PA" <?php echo remind_select('Motif_evenement', 'PA'); ?>>Plus d’assuré au contrat</option>
        <option value="RE" <?php echo remind_select('Motif_evenement', 'RE'); ?>>Renonciation</option>
        <option value="S" <?php echo remind_select('Motif_evenement', 'S'); ?>>Sinistre</option>
      </select-->
        <select name="Motif_evenement" id="Motif_evenement" onchange="Choix(document.forms['form2']);">
            <?php do { ?>
                <option value="<?php echo $row_rs_dico2['Code_element']; ?>" <?php echo remind_select('Motif_evenement', $row_rs_dico2['Code_element']) ?> >
                    <?php echo $row_rs_dico2['Nom_element']; ?>
                </option>
            <?php } while($row_rs_dico2 = mysql_fetch_assoc($rs_dico2)); ?>
        </select>
      </td>
    </tr>
    <tr>
      <td>DATE RESILIATION</td>
      <td><input class="resize_2 dateFo" type="text" name="Date_evenement" value="<?php echo remind_text('Date_evenement'); ?>" size="32" maxlength="10" /></td>
    </tr>
    <tr>
      <td>MONTANT COTISATION RESTANT DUE</td>
      <td><input class="resize_2" type="text" name="Restant_due" value="<?php if(isset($cotisationDue) && !empty($cotisationDue)){ echo $cotisationDue;}else{ echo remind_text('Restant_due_2'); } ?>" size="32" maxlength="10" disabled="disabled" /></td>
    </tr>
    <tr>
      <td>DONT IMPAYES</td>
      <td><input class="resize_2" type="text" name="Dont_impaye" value="<?php if(isset($dontImpayes) && !empty($dontImpayes)){ echo $dontImpayes; }else{ echo remind_text('Dont_impaye_2'); } ?>" size="32" maxlength="10" disabled="disabled" /></td>
    </tr>
  </table>
    </div>
</div>
<div class="imgright"></div>				
<div class="cleared"></div>

<div class="bt1">
	<a href="../../menu.php">
		<span class="btleft"></span>
    	<span class="btmiddle">Retour</span>
    	<span class="btright"></span>
    </a>
</div>
<div class="bt">
<?php if(isset($_POST["Motif_evenement"]) && ($_POST["Motif_evenement"]=='RE') && isset($_POST['Identifiant_contrat']) && isset($_POST['Identifiant_cotisation'])){	?>
	<a id="modifAct" class="afficher" href="remboursementCotisation.php?Identifiant_contrat=<?php echo $_POST['Identifiant_contrat']; ?>&Identifiant_cotisation=<?php echo $_POST['Identifiant_cotisation']; ?>">
<?php }else{ ?>
	<a id="modifAct" class="afficher" href="#">
<?php } ?>
		<span class="btleft"></span>
    	<span class="btmiddle">Remboursement</span>
    	<span class="btright"></span>
    </a>
</div>
<div class="bt">
	<a href="../../menu.php">
    	<span class="btleft"></span>
        <span class="btmiddle">Annuler</span>
        <span class="btright"></span>
    </a>
</div>
<div class="bt">
	<span class="btleft"></span>
    <input type="submit" name="Valider" value="Valider" class="resizeall btmiddle"/>
    <span class="btright"></span>
</div>

<?php 
	if(isset($idCotisation) && !empty($idCotisation) && isset($identifiantContrat) && !empty($identifiantContrat)){ 
		$contrat_ID = $identifiantContrat; 
		$cotisation_ID = $idCotisation;
	}
	
	if(isset($contrat_ID)){ 
		$idContrat = $contrat_ID; 
	}elseif(isset($_POST['Identifiant_contrat'])){ 
		$idContrat = $_POST['Identifiant_contrat'];
	}elseif(isset($_POST['Numero_contrat'])){ 
		$idContrat = IdContrat($database_microassur, $microassur, $_POST['Numero_contrat']);
	}
	
	if(isset($idContrat)){
		$numContrat = NumContrat($database_microassur, $microassur, $idContrat);
	}
?>

  <input type="hidden" name="Identifiant_evenement" value="" />
  <input type="hidden" name="Type_evenement" value="G" />
  <input type="hidden" name="Sous_type_evenement" value="ARE" />
  <input type="hidden" name="Reference_evenement" value="" />
  <input type="hidden" name="Identifiant_agent" value="<?php echo $_SESSION['iduser']; ?>" />
  <input type="hidden" name="Identifiant_sinistre" value="" />
  <input type="hidden" name="Identifiant_contrat" value="<?php echo $idContrat;  //if(isset($contrat_ID)){ echo $contrat_ID; }elseif(isset($_POST['Identifiant_contrat'])){ echo $_POST['Identifiant_contrat']; } ?>" />
  <input type="hidden" name="Identifiant_personne" value="" />
  <input type="hidden" name="Identifiant_echeance" value="" />
  <input type="hidden" name="Identifiant_prestation" value="" />
  
  <input type="hidden" name="Numero_contrat" value="<?php echo $numContrat; ?>" />

  <input type="hidden" name="Restant_due_2" value="<?php if(isset($cotisationDue) && !empty($cotisationDue)){ echo $cotisationDue;}else{ echo remind_text('Restant_due_2'); } ?>" />
  <input type="hidden" name="Dont_impaye_2" value="<?php if(isset($dontImpayes) && !empty($dontImpayes)){ echo $dontImpayes;}else{ echo remind_text('Dont_impaye_2'); } ?>" />
  
  <input type="hidden" name="Identifiant_cotisation" value="<?php if(isset($cotisation_ID)){ echo $cotisation_ID; }elseif(isset($_POST['Identifiant_cotisation'])){ echo $_POST['Identifiant_cotisation']; } ?>" />
  
  <input type="hidden" name="MM_insert" value="form2" />
</form>
 </div>

		<script language="Javascript">
		<!-- 
			/*
			// Afficher le bouton "Remboursement"	
			function afficher() {
			 	var btn = document.getElementById("modifAct");
			 	btn.className= "afficher";
			}
			// Cacher le bouton "Remboursement"
			function cacher() {
			 	var btn = document.getElementById("modifAct");
			 	btn.className= "cacher";
			} 
			function modifierAct1(){ 
				//var idContrat = document.getElementById('identifiant_contrat').value; 
				//var idCotisation = document.getElementById('identifiant_cotisation').value;
				var modifAct = document.getElementById("modifAct");
				<?php if(isset($identifiantContrat) && isset($idCotisation)){ ?>
					modifAct.href = 'remboursementCotisation.php?Identifiant_contrat=<?php echo $identifiantContrat; ?>&Identifiant_cotisation=<?php echo $idCotisation; ?>' ;
				<?php }elseif(isset($_POST['identifiant_contrat']) && isset($_POST['identifiant_cotisation'])){	?>
					modifAct.href = 'remboursementCotisation.php?Identifiant_contrat=<?php echo $_POST['identifiant_contrat']; ?>&Identifiant_cotisation=<?php echo $_POST['identifiant_cotisation']; ?>' ;				
				<?php }else{ ?>
					modifAct.href = '#';
				<?php } ?>
				
				//if(idContrat && idCotisation){
				//	modifAct.href = 'remboursementCotisation.php?Identifiant_contrat='+ idContrat +'&Identifiant_cotisation='+ idCotisation ;				
				//}
			}
			function modifierAct2(){
				var modifAct = document.getElementById("modifAct");
				modifAct.href = '#' ;
			}
			function Choix(formulaire) {
				i = formulaire.Motif_evenement.selectedIndex;
				if(i == 5){
					modifierAct1();
					var idContrat = document.getElementById('identifiant_contrat').value; 
					var idCotisation = document.getElementById('identifiant_cotisation').value;
					var modifAct = document.getElementById("modifAct");
					modifAct.href = 'remboursementCotisation.php?Identifiant_contrat='+ idContrat +'&Identifiant_cotisation='+ idCotisation ;												

					afficher();
				}else{
					modifierAct2();
					afficher(); 
				}
			}*/	
		//-->
		</script>
<script type="text/javascript">
<!--
	/*$(document).ready(function(){
		$("#Motif_evenement").change(function(){
			v =  $("#Motif_evenement option:selected").val(); 
			//t =  $("#Motif_evenement option:selected").text(); 
			var contrat = $('#identifiant_contrat').val(); 
			var cotisation = $('#identifiant_cotisation').val();
			if(contrat && cotisation && v=='RE')
				$('#modifAct').attr('href', 'remboursementCotisation.php?Identifiant_contrat='+ contrat +'&Identifiant_cotisation='+ cotisation); 
			else
				$('#modifAct').attr('href', '#');
		});
	});*/
//-->
</script>

</body>
</html>
<?php 
if(isset($rs1))
	mysql_free_result($rs1);

if(isset($rs_lab_personne))
	mysql_free_result($rs_lab_personne);

ob_end_flush();

?>
